﻿@{
    Layout = "~/Views/Samples/Generic/_Codebehind.cshtml";
}
@section cs_webforms_new
{
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                IList<@(ViewBag.Project.Name).Storage.SqlFile> files = new @(ViewBag.Project.Name).Storage.SqlFileRepository("customSqlServer").GetAll(true);

                if (files.Count > 0)
                {
                    filesRepeater.DataSource = files;
                    filesRepeater.DataBind();

                    existingFilesPanel.Visible = true;
                }
            }
            catch (Exception ex)
            {
                errorMessage.InnerHtml += ex.GetType().FullName + ": " + ex.Message;
                errorMessage.Visible = true;

                uploadPanel.Visible = false;
                uploadResultPanel.Visible = false;
            }
        }
}
@section vb_webforms_new {
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try
                Dim files As IList(Of @(ViewBag.Project.Name).Storage.SqlFile) = New @(ViewBag.Project.Name).Storage.SqlFileRepository("customSqlServer").GetAll(true)

                If files.Count > 0 Then
                    filesRepeater.DataSource = files
                    filesRepeater.DataBind()

                    existingFilesPanel.Visible = true
                End If
            Catch ex As Exception
                errorMessage.InnerHtml += ex.GetType().FullName + ": " + ex.Message
                errorMessage.Visible = true

                uploadPanel.Visible = false
                uploadResultPanel.Visible = false
            End Try
        End Sub
}

@section cs_mvc_initmodel
{
    try
    {
        model.ExistingFiles = new @(ViewBag.Project.Name).Storage.SqlFileRepository("customSqlServer").GetAll(true);
    }
    catch (Exception ex)
    {
        model.Exception = ex;
    }
}

@section cs_mvc_new
{
        public ActionResult Download(int id)
        {
            @(ViewBag.Project.Name).Storage.SqlFileRepository repository = new @(ViewBag.Project.Name).Storage.SqlFileRepository("customSqlServer");
            @(ViewBag.Project.Name).Storage.SqlFile file = repository.GetById(id);

            return File(repository.GetDataStream(file), "application/octet-stream", file.Name);
        }
}

@section vb_mvc_initmodel
{
    Try
        model.ExistingFiles = New @(ViewBag.Project.Name).Storage.SqlFileRepository("customSqlServer").GetAll(true)   
    Catch ex As Exception
        model.Exception = ex
    End Try
}

@section vb_mvc_new
{
        Public Function Download(id As Integer) As ActionResult
            Dim repository As @(ViewBag.Project.Name).Storage.SqlFileRepository = New @(ViewBag.Project.Name).Storage.SqlFileRepository("customSqlServer")
            Dim f As @(ViewBag.Project.Name).Storage.SqlFile = repository.GetById(id)

            Return File(repository.GetDataStream(f), "application/octet-stream", f.Name)
        End Function
}